<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$exchange = 'Gaming';
try {
    $connection = new AMQPStreamConnection('127.0.0.1', 5672, 'guest', 'guest', 'test');

    $channel = $connection->channel();
    $channel->exchange_declare($exchange, 'direct', false, false, false);
    for ($i = 0; $i < 100; $i++) {
        $routes = ['dota', 'csgo', 'lol'];
        $key = array_rand($routes);
        $arr = [
            'match_id' => $i,
            'status' => rand(0,3)
        ];
        $data = json_encode($arr);
        $msg = new AMQPMessage($data);

        $channel->basic_publish($msg, $exchange, $routes[$key]);
        echo '发送 '.$routes[$key].' 消息: ' . $data . PHP_EOL;
    }
    $channel->close();
    $connection->close();
}catch (Exception $e){
    var_dump($e);

}

